#include <stdio.h>

struct date
{
    int year;
    int month;
    int day;
};

struct time
{
    int hour;
    int minute;
    int second;
};

/* 包含数组的结构体 */
struct month
{
    int dayOfMonth;
    char name[3];
};

/* 包含结构体的结构体 */
struct dayAndTime
{
    struct date sdate;
    struct time stime;
};

/* 结构体变体 */
struct people
{
    int age;
    struct date birthday;
} tiger, smartown;

int main(void)
{
    //初始化结构体
    struct date date1 = {2017, 8, 31};
    struct date date2 = {2017, 8};
    //.menber=value
    struct date date3 = {.year = 2017, .month = 8, .day = 31};
    struct date date4 = {.year = 2017, .day = 31};
    //复合字面量
    date1 = (struct date){2017, 9, 1};
    date1 = (struct date){.year = 2017, .month = 9, .day = 1};
    //结构体数组
    struct date dates[5] = {{2017, 8, 29}, {.year = 2017, .month = 8, .day = 31}, {2017, 8}};
    dates[4] = (struct date){.year = 2017, .month = 9, .day = 1};
    //包含结构体的结构体
    struct dayAndTime now =
        {
            .sdate = {2017, 8, 31},
            .stime = {.hour = 10, .minute = 35}};
    now.stime.second = 10;
    printf("now is %.2i/%.2i/%.2i %.2i:%.2i:%.2i\n", now.sdate.year, now.sdate.month, now.sdate.day, now.stime.hour, now.stime.minute, now.stime.second);
    //包含数组的结构体
    struct month months[12];
    months[0] = (struct month){
        31, {'J', 'a', 'n'}};
    printf("%i %c%c%c\n", months[0].dayOfMonth, months[0].name[0], months[0].name[1], months[0].name[2]);
}